# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rsync
pkgver=3.2.2
pkgrel=0
pkgdesc="A file transfer program to keep remote files in sync"
url="https://rsync.samba.org/"
arch="all"
license="GPL-3.0-or-later"
makedepends="perl acl-dev attr-dev popt-dev zlib-dev zstd-dev"
subpackages="$pkgname-doc $pkgname-openrc rrsync"
source="https://download.samba.org/pub/rsync/rsync-$pkgver.tar.gz
	rsyncd.initd
	rsyncd.confd
	rsyncd.conf
	rsyncd.logrotate
	"

# secfixes:
#   3.1.2-r7:
#     - CVE-2017-16548
#     - CVE-2017-17433
#     - CVE-2017-17434

# delete the itemize test because it is flawed and depends on filesystem-specific behavior
prepare() {
	default_prepare
	rm testsuite/itemize.test
}

build() {
	# Force IPv6 enabled, upstream bug https://bugzilla.samba.org/show_bug.cgi?id=10715
	CFLAGS="$CFLAGS -DINET6" \

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-acl-support \
		--enable-xattr-support \
		--without-included-popt \
		--without-included-zlib \
		--disable-lz4 \
		--disable-xxhash \
		--disable-openssl
		# lz4, xxhash and openssl support were implicitly disabled before via automagic
		# since nobody complained that those features were missing starting with 3.2.x
		# they cause errors unless they are expilcitly disabled. If you need those
		# features then open a MR
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/rsyncd.initd "$pkgdir"/etc/init.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.conf "$pkgdir"/etc/rsyncd.conf
	install -Dm644 "$srcdir"/rsyncd.confd "$pkgdir"/etc/conf.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.logrotate "$pkgdir"/etc/logrotate.d/rsyncd
}

rrsync() {
	pkgdesc="Restricted rsync, restricts rsync to a subdir declared in .ssh/authorized_keys"
	depends="rsync perl"
	arch="noarch"

	cd "$builddir"
	install -D -m 755 ./support/rrsync "$subpkgdir"/usr/bin/rrsync
}

sha512sums="78107cf423e9259a7f7e9bf5527a956b648107aba72ea88b4267ae6334539342501d3c060efbc87235563b0253a12c382c4bb1f73335e68a62ff53aa905f9169  rsync-3.2.2.tar.gz
a970a1a991df32ea28678791d6599f3302e32e2c5c53f44fae567c191db7951bc07e4001f34864fec63e0005dcaa5dc939e77edf652481ff8820e7f422895dfb  rsyncd.initd
94308fa7c0f80156d0863a446ec4630afeafed7b458c6c83e93aba41192327d113b712cde875ce2967bc98cd8fb6a9ebc57841d58ae9759aa232643fb72fb005  rsyncd.confd
3db8a2b364fc89132af6143af90513deb6be3a78c8180d47c969e33cb5edde9db88aad27758a6911f93781e3c9846aeadc80fffc761c355d6a28358853156b62  rsyncd.conf
b8d6c0bb467a5c963317dc55478d2c10874564cd264d943d4a42037e2fce134fe001fabc92af5c6b5775e84dc310b1c8da147afaa61c99e5663c36580d8651a5  rsyncd.logrotate"
